<style>
    tr th{
        cursor:pointer;
    }
</style>
<?php
use common\helps\formatMoney;
$state = Yii::$app->request->get('packageState',123);
//$countryList = \common\models\Country::getTitleList();
$countData = 0;
switch ($state){
    case Yii::$app->params['ALL'] :
        $countData = $userPackageCount['allState'];
        break;
    case Yii::$app->params['NONE'] :
        $countData = $userPackageCount['wuState'];
        break;
    case  Yii::$app->params['YUPINGGU'] :
        $countData = $userPackageCount['qidongState'];
        break;
    case  Yii::$app->params['LIXIANGSHENPIN'] :
        $countData = $userPackageCount['lixiangState'];
        break;
    case  Yii::$app->params['TOUQIANJINDIAO'] :
        $countData = $userPackageCount['pingguState'];
        break;
    case  Yii::$app->params['DAIGENJIN'] :
        $countData = $userPackageCount['shourangState'];
        break;
    default:
        $countData = $userPackageCount['allState'];
        break;
}
if ($countData > 0) {
    if ($packageGroup == 2) {
        $button = '<button class = "myactive pull-right uploadProjectExcel" id="uploadProjectExcel">上传项目清单</button>';
    } else {
        $button = '<button class = "myactive pull-right modifySynergy" id="saveXietong"  >修改协同</button>';
    }

    echo '<div class="top revise  clearfix">
            <button class="pull-right modificationSynergy" id="setPermission" data-toggle="modal" data-target="#myModal">修改访问权限</button>
            '. $button .'
            </div>
            <table class="mytable" border="" cellspacing="" cellpadding="">
                <thead class="thead-normal">
            		 <tr class="top tableTh">
	                    <th class=""></th>
	                    <th class="" onclick="orderGroup(1)">资产包名称</th>
	                    <th class="" onclick="orderGroup(3)"> 本金</th>
	                    <th class="" onclick="orderGroup(5)">利息</th>
	                    <th class="" onclick="orderGroup(7)">剩余户数</th>
	                    <th class="" onclick="orderGroup(9)">省份地区</th>
	                    <th class="" onclick="orderGroup(11)">资产包负责人</th>
	                    <th class="" onclick="orderGroup(13)">上传时间</th>
	                    <th class="" onclick="orderGroup(15)">当前状态</th>
	                    <th class="" onclick="orderGroup(17)">尽调成员</th>
	                    <th class="">详情</th>
	                </tr>
            	</thead>
            	<thead class="thead-fixed" style="border-bottom: 1px solid #E2E2E2">
            		 <tr class="top tableTh">
	                   <th class=""></th>
	                    <th class="" onclick="orderGroup(1)">资产包名称</th>
	                    <th class="" onclick="orderGroup(3)"> 本金</th>
	                    <th class="" onclick="orderGroup(5)">利息</th>
	                    <th class="" onclick="orderGroup(7)">剩余户数</th>
	                    <th class="" onclick="orderGroup(9)">省份地区</th>
	                    <th class="" onclick="orderGroup(11)">资产包负责人</th>
	                    <th class="" onclick="orderGroup(13)">上传时间</th>
	                    <th class="" onclick="orderGroup(15)">当前状态</th>
	                    <th class="" onclick="orderGroup(17)">尽调成员</th>
	                    <th class="">详情</th>
	                </tr>
            	</thead>';


    foreach ($userPackageData['data']['res'] as $k => $v) {
        $id = empty($v['package_id'])?$v['id']:$v['package_id'];
        $code = $v['code'];
        $title = !empty($v['title'])?$v['title']:'--';
        $principal = !empty($v['principal'])?formatMoney::format_money($v['principal'],2):0.00;
        $interest = !empty($v['interest'])?$v['interest']:'--';
        $interest      = !empty($interest)?formatMoney::format_money($interest,2):0.00;
        $hushu = !empty($v['hushu'])?$v['hushu']:'--';
        $province = !empty($v['provinceName']['title'])?$v['provinceName']['title']:'--';
        //$city = !empty($v['cityName']['title'])?$v['cityName']['title']:'-';
//        if ($v['city'] != '') {
//            $arr = explode(',', $v['city']);
//            $array = array();
//            if (!empty($arr)) {
//                foreach ($arr as $value) {
//                    $array[] = $countryList[(int)$value];
//                }
//            }
//            $city = join('、',$array);
//        } else {
//            $city = '';
//        }
        $city = !empty($v['cityNameList']) ? $v['cityNameList'] : '';

        $owner =  !empty($v['owner'])?$v['owner']:'';
        $leader = !empty($v['leader'])?$v['leader']:'';
        $due_diligence = !empty($v['due_diligence'])?$v['due_diligence']:'';
        $state  = Yii::$app->params['package_state'][$v['state']];
        $messageState = !empty($v['message_state'])?$v['message_state']:1;  //消息状态 2未阅读 1阅读
        $message_user_group_id = !empty($v['message_user_group_id'])?$v['message_user_group_id']:'--';
        $created_at = !empty($v['created_at'])?  date('Y/m/d',strtotime($v['created_at'])):'';


        $userArr = (new \yii\db\Query())->from('user')->all();
        $leaderName = '--';
        $leaderid = 0;
        $leaderId = array_filter(explode(',',$leader));
        if (array_key_exists('0',$leaderId)){
            if(!empty($leaderId[0]))     $leaderid = $leaderId[0];
        }
        if (array_key_exists('1',$leaderId)){
            if(!empty($leaderId[1]))   $leaderid = $leaderId[1];
        }
        if (empty($leaderid)){
            $leaderid = $v['leader'];
        }
        if (!empty($leader)) {
            foreach ($userArr as $k1 => $v1) {
                if ($v1['id']==$leaderid){
                    $leaderName = $v1['realname'];
                }
            }
        } else{
            foreach ($userArr as $k1 => $v1) {
                if ($v1['id']==$owner){
                    $leaderName = $v1['realname'];
                }
            }
        }
        $due_diligenceNmae = $due_diligenceSName= '';
        $due_diligenceId = array_filter(explode(',',$due_diligence));
        if (!empty($due_diligence)) {
            foreach ($due_diligenceId as $k => $v) {
                foreach ($userArr as $k1 => $v1) {
                    if ($v1['id']==$v){
                        $due_diligenceNmae.= $v1['realname'].' ';
                    }
                }
            }
            $due_diligenceSName = mb_substr($due_diligenceNmae,0,15);
        }
        $isView = \backend\controllers\DtActionFilter::checkPackage('package_view',$id);
        $url = '/package/detail-info?packageid='.$id.'&message_state='.$messageState.'&message_user_group_id='.$message_user_group_id;
        if ($isView){
            $viewHtml =  <<<ISVIEW
        <a href="$url" target="_blank">查看</a>
ISVIEW;
        }else{
            $viewHtml =  <<<ISVIEW
                        <a href="javascript:void(0)" class="fangwenSQ" data-packageid="$id">申请访问</a>
ISVIEW;
        }
        $tr = <<<TR
<tr>
    <td>
    	
        <input type="checkbox" id = "choice" value="$id"/>
        <label class="choiceimg" for="choice">
            <!--<img  src="image/myAssetBag/false1.png" alt="单击选中" />-->
        </label>

    </td>
    <td>
    	<span class='txt-cut' title="$title">
    		$title
    	</span>
    </td>
    <td>
    	<span class='txt-cut'>
    		$principal
    	</span>
    </td>
    <td>
    	<span class='txt-cut'>
    		$interest
    	</span>
    </td>
    <td>
    	<span class='txt-cut'>
    		$hushu
    	</span>
    </td>
    <td>
    	<span class='txt-cut' title='$province&nbsp;&nbsp;$city'>
    		$province&nbsp;&nbsp;$city
    	</span>
    </td>
    <td>
 	<span class='txt-cut' title="$leaderName">
    		    	$leaderName
    	</span>
    </td>
        <td>
 	<span class='txt-cut' title="$created_at">
    		    	$created_at
    	</span>
    </td>
    <td>
    	<span class="txt-cut project " title="$state">$state</span>
    </td>
    <td>
    	<span class='txt-cut' title="$due_diligenceNmae">
    		$due_diligenceSName
    	</span>
    </td>
    <td>        
		$viewHtml
    </td>
</tr>
TR;
        echo $tr;
    }
}else{
    echo <<<NOTEXT
<div class="defaultPage">
		<div class="defaultPage-nothing">
			<img src="/image/defaultPage/nothing.png" style='width: 100%;'>
		</div>
	</div>
NOTEXT;
    ;
}
?>
</table>
<script>
    function orderGroup(valOrder) {
        var valOrderGet = '<?=  Yii::$app->request->get('orderGroup',0);?>';
        if (valOrder==1&&valOrder==valOrderGet){
            valOrder = 2;
        }
        if (valOrder==3&&valOrder==valOrderGet){
            valOrder = 4;
        }
        if (valOrder==5&&valOrder==valOrderGet){
            valOrder = 6;
        }
        if (valOrder==7&&valOrder==valOrderGet){
            valOrder = 8;
        }
        if (valOrder==9&&valOrder==valOrderGet){
            valOrder = 10;
        }
        if (valOrder==11&&valOrder==valOrderGet){
            valOrder = 12;
        }
        if (valOrder==13&&valOrder==valOrderGet){
            valOrder = 14;
        }
        if (valOrder==15&&valOrder==valOrderGet){
            valOrder = 16;
        }
        if (valOrder==17&&valOrder==valOrderGet){
            valOrder = 18;
        }
        var packageGroup = '<?=  Yii::$app->request->get('packageGroup',1);?>';
        var keywords ='<?=  Yii::$app->request->get('keywords','');?>';
        var packageState ='<?=  Yii::$app->request->get('packageState',123);?>';
        var showNumOne = '<?=  Yii::$app->request->get('showNum',10);?>';

        var url = '/my-package/get-my-package?packageGroup='+packageGroup+'&keywords='+keywords+'&packageState='+packageState+'&showNum='+showNumOne+'&orderGroup='+valOrder;

        window.location.href = url;
    }
</script>